<?php
namespace app\common\Controller;

use think\Controller;

use app\common\lib\ArrayToXML;
use app\common\lib\ENC;
use app\common\lib\Snoopy;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/26
 * Time: 16:10
  */

class Jinyuntong extends Controller
{
    private $accountkey = "8Q9ZQ94KF539UI1G3BH0SA8CMIW0LQaxgece";
    private $account = "201510261536537283";
    private $simulateMode = false;
//金运通商户ID  测试环境
    private $jyttestID = '100060100008';
//金运通商户ID  生产环境
    private $jytID = "100060100021";
    //实名支付 接口  生产
    //private  $shimingUrl="https://www.jytpay.com:9410/JytRNPay/tranCenter/encXmlReq.do";//旧的
    private  $shimingUrl="https://rnpay.jytpay.com/JytRNPay/tranCenter/encXmlReq.do";//最新
    private  $shimingtestUrl="http://test1.jytpay.com:16080/JytRNPay/tranCenter/encXmlReq.do";
    //代收付 接口   生产
    private  $daishoufuUrl="https://www.jytpay.com:9010/JytCPService/tranCenter/encXmlReq.do";
    //鉴权接口 测试
    private  $jianquantestUrl="http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do";
    //鉴权接口 生产
    private  $jianquanUrl="https://www.jytpay.com:9210/JytAuth/tranCenter/authReq.do";


//    绑卡
    public function bangka($params='',$amount='',$jyttype=''){
        header("Content-Type:text/html;charset=utf-8");
        date_default_timezone_set('PRC');  // 设置时区
        /* 0. 请根据对接产品类型和实际商户号修改如下信息  */
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';  // 交易请求URL
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';
        $url = $this->shimingUrl;
        //$url = 'http://10.10.10.103:20080/JytAuth/trantestCenter/authReq.do';  // 交易请求URL
        $merchant_id = $this->jytID;                                     // 交易商户号
        $mer_pri_file ='D:/product/91duandai/application/integrate/cert/jytcert/rsa_private_key_2048.pem';// 商户RSA私钥
        $pay_pub_file = 'D:/product/91duandai/application/integrate/cert/jytcert/rsa_public_key_2048.pem';// 平台RSA公钥
        $m = new ENC($pay_pub_file, $mer_pri_file);
		

//        $params=count($_POST)?$_POST:$params;
        /* 1. 组织报文头  */
        $req_param['merchant_id'] = $merchant_id;
        $req_param['tran_type'] = '01';
        $req_param['version'] = '1.0.0';
        $req_param['tran_flowid'] = $req_param['merchant_id'] . date('YmdHis') . rand(10000, 99999); // 请根据商户系统自行定义订单号
        $req_param['tran_date'] = date('Ymd');
        $req_param['tran_time'] = date('His');

        /* 2. --- 请根据接口报文组织请求报文体 ，下面例子为身份认证交易请求报文体，请按照实际交易接口填充内容 */
        $req_param['tran_code'] =$jyttype;



        if($jyttype=="TD1005"){
            $req_body['cust_no'] = $params['cust_no'];
            $req_body['order_id'] = $params['order_id'];
            $req_body['bank_card_no'] = $params['bank_card_no'];
            $req_body['id_card_no'] = $params['id_card_no'];
            $req_body['mobile'] = $params['mobile'];
            $req_body['name'] = $params['name'];
            $req_body['tran_amount'] =$amount;
        }elseif($jyttype=="TD4006"){
            $req_body['bind_order_id'] = session('bind_order_id');
            $req_body['verify_code']=$params['verify_code'];
            $req_body['mobile'] =$params['mobile'];
        }elseif($jyttype=="TD1002"){
            $req_body['cust_no'] = $params['cust_no'];
            $req_body['order_id'] =$params['order_id'];
            $req_body['bank_card_no'] = $params['bank_card_no'];
            $req_body['tran_amount'] = $amount;
        }elseif($jyttype=="TD4004"){
            $req_body['order_id'] = $params['order_id'];
            $req_body['verify_code']=$params['verify_code'];
            $req_body['mobile'] =$params['mobile'];
        }elseif($jyttype=="TD4003"){
            $req_body['order_id'] =$params['order_id'];
            $req_body['mobile'] ==$params['mobile'];
        }elseif($jyttype=="TD1001"){
            $req_body['cust_no'] = $params['cust_no'];
            $req_body['order_id'] = $params['order_id'];
            $req_body['bank_card_no'] = $params['bank_card_no'];
            $req_body['id_card_no'] = $params['id_card_no'];
            $req_body['mobile'] = $params['mobile'];
            $req_body['name'] = $params['name'];
            $req_body['tran_amount'] =$amount;
        }elseif($jyttype=="TD4001"){
            $req_body['order_id'] =$params['order_id'];
            $req_body['mobile'] = $params['mobile'];
			$req_body['verify_code']=$params['verify_code'];
        }
        /* 3. 转换请求数组为xml格式 */
        $data = array(
            "head" => $req_param,
            "body" => $req_body
        );
        //file_put_contents('D:\product\91duandai\Application\Integrate\3.php',var_export($data,TRUE));
        $xml_ori = ArrayToXML::toXml($data);
		//file_put_contents('D:\product\91duandai\Application\Integrate\10.php',var_export($xml_ori,TRUE));
        /* 4. 组织POST字段 */
        $req['merchant_id'] = $req_param['merchant_id'];
        $req['sign'] = $m->sign($xml_ori, 'hex');
        $key = rand(pow(10, (8 - 1)), pow(10, 8) - 1);
        $req['key_enc'] = $m->encrypt($key, 'hex');
        $req['xml_enc'] = $m->desEncrypt($xml_ori, $key);

        /* 5. post提交到支付平台 */
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $req = http_build_query($req);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $req);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($curl);
        curl_close($curl);
        /* 6. 正则表达式分解返回报文 */
// preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $snoopy->results, $matches );

        preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $result, $matches);
        $xml_enc = $matches[2];
        $key_enc = $matches[3];
        $sign = $matches[4];

        /* 7. 解密并验签返回报文 */
        $key = $m->decrypt($key_enc, 'hex');
        $xml = $m->desDecrypt($xml_enc, $key);
		//file_put_contents('D:\product\91duandai\Application\Integrate\2.php',var_export($xml,TRUE));
        if (!$m->verify($xml, $sign, 'hex')) {
            echo  json_encode(['status'=>3,'msg'=>"系统错误"]);
        }else {
			//echo  json_encode(['status'=>1]);
            $a = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $step1 = json_decode(json_encode($a), ture);
        }
		//$han = array($jyttype,$data,$step1);
		file_put_contents('D:\product\91duandai\Application\Integrate\13.php',var_export($step1,TRUE),FILE_APPEND);
       
	   return $step1;
    }

	    public function test13123(){
        $_POST['u_bankno']='6214830169023263';
        $_POST['name']='宋科科';
        $_POST['idcard']='140511199208161232';
        $_POST['u_bankphone']='18401477305';
        self::bangka($_POST);

    }

//实名认证
    public function smrz(){
        header("Content-Type:text/html;charset=utf-8");
        date_default_timezone_set('PRC');  // 设置时区
        /* 0. 请根据对接产品类型和实际商户号修改如下信息  */
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';  // 交易请求URL
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';
        $url = $this->jianquanUrl;
        //$url = 'http://10.10.10.103:20080/JytAuth/trantestCenter/authReq.do';  // 交易请求URL
        $merchant_id = $this->jytID;                                     // 交易商户号
        $mer_pub_file='D:/product/91duandai/application/integrate/cert/jytcert/tsrsa_public_key_2048.pem';
        $mer_pri_file ='D:/product/91duandai/application/integrate/cert/jytcert/rsa_private_key_2048.pem';                        // 商户RSA私钥
        $pay_pub_file = 'D:/product/91duandai/application/integrate/cert/jytcert/rsa_public_key_2048.pem';                        // 平台RSA公钥
        $m = new ENC($pay_pub_file, $mer_pri_file);
//        $_POST=$a;
//        $params=count($_POST)?$_POST:$params;
        /* 1. 组织报文头  */
        $req_param['merchant_id'] = $merchant_id;
        $req_param['tran_type'] = '01';
        $req_param['version'] = '1.0.0';
        $req_param['tran_flowid'] = $req_param['merchant_id'] . date('YmdHis') . rand(10000, 99999); // 请根据商户系统自行定义订单号
        $req_param['tran_date'] = date('Ymd');
        $req_param['tran_time'] = date('His');

        /* 2. --- 请根据接口报文组织请求报文体 ，下面例子为身份认证交易请求报文体，请按照实际交易接口填充内容 */
        $req_param['tran_code'] = 'TR4003';

        $req_body['bank_card_no'] = $_POST['u_bankno'];
        $req_body['id_name'] = $_POST['name'];

        $req_body['bank_card_type'] = 'D';
        $req_body['id_num'] =  $_POST['idcard'];
        $req_body['phone_no'] = $_POST['u_bankphone'];
        $req_body['terminal_type'] = '02';
//        dump($req_body);
//        $req_body['remark'] = '摘要信息'; // 可为空
//        $req_body['reserve'] = '预留字段'; // 可为空
        /* 3. 转换请求数组为xml格式 */
        $data = array(
            "head" => $req_param,
            "body" => $req_body
        );
        $xml_ori = ArrayToXML::toXml($data);
        /* 4. 组织POST字段 */
        $req['merchant_id'] = $req_param['merchant_id'];
        $req['sign'] = $m->sign($xml_ori, 'hex');
        $key = rand(pow(10, (8 - 1)), pow(10, 8) - 1);
        $req['key_enc'] = $m->encrypt($key, 'hex');
        $req['xml_enc'] = $m->desEncrypt($xml_ori, $key);

        /* 5. post提交到支付平台 */
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $req = http_build_query($req);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $req);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($curl,  CURLOPT_SSL_VERIFYHOST,false);
        $result = curl_exec($curl);
//        dump(curl_error($curl));
        curl_close($curl);
//        dump($result);
        /* 6. 正则表达式分解返回报文 */
// preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $snoopy->results, $matches );

        preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $result, $matches);
        $xml_enc = $matches[2];
        $key_enc = $matches[3];
        $sign = $matches[4];

        /* 7. 解密并验签返回报文 */
        $key = $m->decrypt($key_enc, 'hex');
        $xml = $m->desDecrypt($xml_enc, $key);
        if (! $m->verify($xml, $sign, 'hex')) {
         echo  json_encode(['status'=>0,'code'=>"系统错误"]);
		 die;
        }else {
            $a = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $step1 = json_decode(json_encode($a),ture);
        }
		
//        dump($step1);
            if($step1['head']["resp_code"]=='S0000000'){
                echo json_encode(['status'=>'1','msg'=>$step1['head']["resp_desc"]]);
            }else{
                echo json_encode(['status'=>'0','msg'=>$step1['head']["resp_desc"]]);
            }

        }

    public function test(){
        $_POST['u_bankno']='6214830169023263';
        $_POST['name']='宋科科';
         $_POST['idcard']='140511199208161232';
        $_POST['u_bankphone']='18401477305';
        self::bangka($_POST);

    }
//解绑
    public function jiebang()
    {
        header("Content-Type:text/html;charset=utf-8");
        date_default_timezone_set('PRC');  // 设置时区
        /* 0. 请根据对接产品类型和实际商户号修改如下信息  */
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';  // 交易请求URL
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';
        $url = $this->shimingUrl;
        //$url = 'http://10.10.10.103:20080/JytAuth/trantestCenter/authReq.do';  // 交易请求URL
        $merchant_id = $this->jytID;                                     // 交易商户号
        $mer_pri_file ='D:/product/91duandai/application/integrate/cert/jytcert/rsa_private_key_2048.pem';                        // 商户RSA私钥
        $pay_pub_file = 'D:/product/91duandai/application/integrate/cert/jytcert/rsa_public_key_2048.pem';                        // 平台RSA公钥
        $m = new ENC($pay_pub_file, $mer_pri_file);

//        $params=count($_POST)?$_POST:$params;
        /* 1. 组织报文头  */
        $req_param['merchant_id'] = $merchant_id;
        $req_param['tran_type'] = '01';
        $req_param['version'] = '1.0.0';
        $req_param['tran_flowid'] = $req_param['merchant_id'] . date('YmdHis') . rand(10000, 99999); // 请根据商户系统自行定义订单号
        $req_param['tran_date'] = date('Ymd');
        $req_param['tran_time'] = date('His');

        /* 2. --- 请根据接口报文组织请求报文体 ，下面例子为身份认证交易请求报文体，请按照实际交易接口填充内容 */
        $req_param['tran_code'] = 'TD4002';

            $req_body['cust_no'] = 'jydd15004555344076';//用户id
			$req_body['bank_card_no'] = '4367420110028390407';//银行卡号

        /* 3. 转换请求数组为xml格式 */
        $data = array(
            "head" => $req_param,
            "body" => $req_body
        );
       
        $xml_ori = ArrayToXML::toXml($data);
        /* 4. 组织POST字段 */
        $req['merchant_id'] = $req_param['merchant_id'];
        $req['sign'] = $m->sign($xml_ori, 'hex');
        $key = rand(pow(10, (8 - 1)), pow(10, 8) - 1);
        $req['key_enc'] = $m->encrypt($key, 'hex');
        $req['xml_enc'] = $m->desEncrypt($xml_ori, $key);

        /* 5. post提交到支付平台 */
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $req = http_build_query($req);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $req);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($curl);
        curl_close($curl);
        /* 6. 正则表达式分解返回报文 */
// preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $snoopy->results, $matches );

        preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $result, $matches);
        $xml_enc = $matches[2];
        $key_enc = $matches[3];
        $sign = $matches[4];

        /* 7. 解密并验签返回报文 */
        $key = $m->decrypt($key_enc, 'hex');
        $xml = $m->desDecrypt($xml_enc, $key);
        dump($xml);

        if (!$m->verify($xml, $sign, 'hex')) {
            echo  json_encode(['atatus'=>0,'code'=>"系统错误"]);
        }else {
            $a = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $step1 = json_decode(json_encode($a), ture);
        }
       return $step1;
    }

    

//查询
    public function search(){
        header("Content-Type:text/html;charset=utf-8");
        date_default_timezone_set('PRC');  // 设置时区
        /* 0. 请根据对接产品类型和实际商户号修改如下信息  */
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';  // 交易请求URL
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';
        $url = $this->shimingUrl;
        //$url = 'http://10.10.10.103:20080/JytAuth/trantestCenter/authReq.do';  // 交易请求URL
        $merchant_id = $this->jytID;                                     // 交易商户号
        $mer_pri_file ='D:/product/91duandai/application/integrate/cert/jytcert/rsa_private_key_2048.pem';                        // 商户RSA私钥
        $pay_pub_file = 'D:/product/91duandai/application/integrate/cert/jytcert/rsa_public_key_2048.pem';                        // 平台RSA公钥
        $m = new ENC($pay_pub_file, $mer_pri_file);

//        $params=count($_POST)?$_POST:$params;
        /* 1. 组织报文头  */
        $req_param['merchant_id'] = $merchant_id;
        $req_param['tran_type'] = '01';
        $req_param['version'] = '1.0.0';
        $req_param['tran_flowid'] = $req_param['merchant_id'] . date('YmdHis') . rand(10000, 99999); // 请根据商户系统自行定义订单号
        $req_param['tran_date'] = date('Ymd');
        $req_param['tran_time'] = date('His');

        /* 2. --- 请根据接口报文组织请求报文体 ，下面例子为身份认证交易请求报文体，请按照实际交易接口填充内容 */
        $req_param['tran_code'] = 'TD2002';

            $req_body['cust_no'] = 'jydd1498790811167';    

        /* 3. 转换请求数组为xml格式 */
        $data = array(
            "head" => $req_param,
            "body" => $req_body
        );
       
        $xml_ori = ArrayToXML::toXml($data);
        /* 4. 组织POST字段 */
        $req['merchant_id'] = $req_param['merchant_id'];
        $req['sign'] = $m->sign($xml_ori, 'hex');
        $key = rand(pow(10, (8 - 1)), pow(10, 8) - 1);
        $req['key_enc'] = $m->encrypt($key, 'hex');
        $req['xml_enc'] = $m->desEncrypt($xml_ori, $key);

        /* 5. post提交到支付平台 */
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $req = http_build_query($req);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $req);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($curl);
        curl_close($curl);
        /* 6. 正则表达式分解返回报文 */
// preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $snoopy->results, $matches );

        preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $result, $matches);
        $xml_enc = $matches[2];
        $key_enc = $matches[3];
        $sign = $matches[4];

        /* 7. 解密并验签返回报文 */
        $key = $m->decrypt($key_enc, 'hex');
        $xml = $m->desDecrypt($xml_enc, $key);
        dump($xml);

        if (!$m->verify($xml, $sign, 'hex')) {
            echo  json_encode(['atatus'=>0,'code'=>"系统错误"]);
        }else {
            $a = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $step1 = json_decode(json_encode($a), ture);
        }
       return $step1;
    }
	
//退款
    public function tuikuan(){
        header("Content-Type:text/html;charset=utf-8");
        date_default_timezone_set('PRC');  // 设置时区
        /* 0. 请根据对接产品类型和实际商户号修改如下信息  */
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';  // 交易请求URL
        //$url = 'http://test1.jytpay.com:20080/JytAuth/tranCenter/authReq.do';
        $url = $this->shimingUrl;
        //$url = 'http://10.10.10.103:20080/JytAuth/trantestCenter/authReq.do';  // 交易请求URL
        $merchant_id = $this->jytID;                                     // 交易商户号
        $mer_pri_file ='D:/product/91duandai/application/integrate/cert/jytcert/rsa_private_key_2048.pem';                        // 商户RSA私钥
        $pay_pub_file = 'D:/product/91duandai/application/integrate/cert/jytcert/rsa_public_key_2048.pem';                        // 平台RSA公钥
        $m = new ENC($pay_pub_file, $mer_pri_file);

//        $params=count($_POST)?$_POST:$params;
        /* 1. 组织报文头  */
        $req_param['merchant_id'] = $merchant_id;
        $req_param['tran_type'] = '01';
        $req_param['version'] = '1.0.0';
        $req_param['tran_flowid'] = $req_param['merchant_id'] . date('YmdHis') . rand(10000, 99999); // 请根据商户系统自行定义订单号
        $req_param['tran_date'] = date('Ymd');
        $req_param['tran_time'] = date('His');

        /* 2. --- 请根据接口报文组织请求报文体 ，下面例子为身份认证交易请求报文体，请按照实际交易接口填充内容 */
        $req_param['tran_code'] = 'TD1003';
			$req_body['order_id'] ='jydd'.time(); 
			$req_body['ori_order_id'] ='jydd2017072819481092996'; 
			$req_body['refund_amt'] =5; 

        /* 3. 转换请求数组为xml格式 */
        $data = array(
            "head" => $req_param,
            "body" => $req_body
        );
       
        $xml_ori = ArrayToXML::toXml($data);
        /* 4. 组织POST字段 */
        $req['merchant_id'] = $req_param['merchant_id'];
        $req['sign'] = $m->sign($xml_ori, 'hex');
        $key = rand(pow(10, (8 - 1)), pow(10, 8) - 1);
        $req['key_enc'] = $m->encrypt($key, 'hex');
        $req['xml_enc'] = $m->desEncrypt($xml_ori, $key);

        /* 5. post提交到支付平台 */
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $req = http_build_query($req);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $req);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($curl);
        curl_close($curl);
        /* 6. 正则表达式分解返回报文 */
// preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $snoopy->results, $matches );

        preg_match('/^merchant_id=(.*)&xml_enc=(.*)&key_enc=(.*)&sign=(.*)$/', $result, $matches);
        $xml_enc = $matches[2];
        $key_enc = $matches[3];
        $sign = $matches[4];

        /* 7. 解密并验签返回报文 */
        $key = $m->decrypt($key_enc, 'hex');
        $xml = $m->desDecrypt($xml_enc, $key);
        dump($xml);
 if (!$m->verify($xml, $sign, 'hex')) {
            echo  json_encode(['atatus'=>0,'code'=>"系统错误"]);
        }else {
            $a = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $step1 = json_decode(json_encode($a), ture);
        }
       return $step1;
    }


}